home *** CD-ROM | disk | FTP | other *** search
- /* AddressOMatic.c */
- /*
- * AddressOMatic Sample
- * AddressOMatic.c
- * Copyright © 1993 Apple Computer Inc. All rights reserved.
- * AddressOMatic is a Trademark of Apple Computer Inc.
- */
- #define _AOM_EXTERN /* */
- #include "AddressOMaticPrivate.h"
- #include <OCEStandardMail.h>
-
- #define TAB '\t'
-
- /*
- * Create an AddressOMatic panel. If the application disables one of the
- * radio buttons, it should pass NULL or zero for the affected parameter.
- */
- pascal OSErr
- AOMNewPanel(
- AddressOMaticPtr *aomPanel, /* Record stored here */
- WindowPtr window, /* Put into this window */
- const Rect *bounds, /* Shape and position */
- Boolean visible, /* Initially visible */
- Boolean enabled, /* Initially enabled */
- AuthIdentity identity, /* Initial identity */
- const RStringPtr *typesList, /* Types to select */
- unsigned long typeCount, /* Number of types */
- void *refCon, /* App owns this value */
- AOMModeMask enableModeMask, /* What can user do? */
- AOMModeBit initialMode, /* Starting with? */
- short stringsResID, /* Labelling strings */
- short browserHelpStringID, /* Browser help string */
- short pdHelpStringID, /* Personal Cat. help */
- short findHelpStringID, /* Find panel help */
- /*
- * The following parameters configure the SDPPanel and Personal Directory
- * Browser.
- */
- const PackedRLI *initialRLI, /* Initially selected */
- DirEnumChoices enumFlags, /* Enumeration flags */
- DirMatchWith matchTypeHow, /* Enumeration mode */
- /*
- * The following parameter configures the SDPFindPanel. Focus is always
- * initially in the text area.
- */
- short simultaneousSearchCount
- #ifdef ENABLE_TYPEIN
- ,
- /*
- * The following parameter configures the TypeIn callback
- */
- const RStringPtr typeInRecordType /* What does it return */
- #endif
- )
- {
-
- OSErr status;
- register AddressOMaticPtr aomPtr;
- AOMSaveState saveState;
-
- aomPtr = (AddressOMaticPtr) NewPtrClear(sizeof (AddressOMaticRecord));
- status = MemError();
- *aomPanel = aomPtr; /* NULL on errors */
- if (aomPtr == NULL || status != noErr)
- goto exit;
- /*
- * Copy user parameters into the AOM record.
- */
- AOM.window = window;
- _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
- BOUNDS = *bounds; /* Location and size */
- AOM.isVisible = visible;
- AOM.isEnabled = enabled;
- AOM.identity = identity;
- AOM.typesList = typesList;
- AOM.typeCount = typeCount;
- AOM.refCon = refCon;
- AOM.currentMode = kAOMUnknownMode;
- /*
- * Lie about the state of the buttons so they will be
- * disabled when we finish creating the panels.
- */
- AOM.enableToButton = TRUE;
- AOM.enableCCButton = TRUE;
- AOM.stringsResID = stringsResID;
- #ifdef ENABLE_TYPEIN
- AOM.typeInRecordType = typeInRecordType;
- #endif
- EraseRect(&BOUNDS);
- status = _AOMCreateButtons(aomPtr, enableModeMask);
- _AOMDecorateDisplay(aomPtr);
- AOMUpdatePanel(aomPtr, NULL);
- ValidRect(&BOUNDS);
- _AOMSetFont(aomPtr, kAOMTextFontStyle); /* Not bold */
- enumFlags &= ~kEnumInvisibleMask;
- if (status == noErr
- && (enableModeMask & kAOMEnablePDMask) != 0) {
- status = _AOMPanelCreate(
- aomPtr,
- typesList,
- typeCount,
- (PackedRLI *) -1,
- enumFlags,
- matchTypeHow,
- pdHelpStringID,
- &AOM.pdPanel
- );
- }
- if (status == noErr
- && (enableModeMask & kAOMEnablePanelMask) != 0) {
- status = _AOMPanelCreate(
- aomPtr,
- typesList,
- typeCount,
- initialRLI,
- enumFlags,
- matchTypeHow,
- browserHelpStringID,
- &AOM.browsePanel
- );
- }
- if (status == noErr
- && (enableModeMask & kAOMEnableFindMask) != 0) {
- status = _AOMFindCreate(
- aomPtr,
- typesList,
- typeCount,
- simultaneousSearchCount,
- kSDPFindPanelTextHasFocus,
- matchTypeHow,
- findHelpStringID
- );
- }
- #ifdef ENABLE_TYPEIN
- if (status == noErr
- && (enableModeMask & kAOMEnableTypeInMask) != 0) {
- status = _AOMTypeInCreate(aomPtr);
- }
- #endif
- _AOMSetFont(aomPtr, kAOMLabelFontStyle);
- if (status == noErr) {
- #ifdef kFirstSpinnerIcon /* Not in Beta 1 */
- AOM.animationSICNIndex = kFirstSpinnerIcon;
- AOM.nextAnimation = TickCount() + kSpinnerDelay;
- #endif
- }
- if (status == noErr) {
- _AOMSelectMode(aomPtr, initialMode);
- _AOMPlotIcon(aomPtr, initialMode, TRUE);
- _AOMSetButtonText(aomPtr);
- }
- else {
- (void) AOMDisposePanel(aomPtr);
- *aomPanel = NULL;
- }
- _AOMRestoreState(&saveState);
- exit: LOG(status, "\pAOMNewPanel exit");
- return (status);
- }
-
- /*
- * Clean up the mess.
- */
- pascal OSErr
- AOMDisposePanel(
- AddressOMaticPtr aomPtr /* The panel */
- )
- {
- OSErr status;
- OSErr returnStatus;
-
- returnStatus = status = noErr;
- if (aomPtr != NULL) {
- if (AOM.pdPanel != NULL)
- status = returnStatus = _AOMPanelDispose(aomPtr, AOM.pdPanel);
- if (AOM.browsePanel != NULL) {
- status = _AOMPanelDispose(aomPtr, AOM.browsePanel);
- if (returnStatus == noErr)
- returnStatus = status;
- }
- if (AOM.findPanel != NULL) {
- status = _AOMFindDispose(aomPtr);
- if (returnStatus == noErr)
- returnStatus = status;
- }
- #ifdef ENABLE_TYPEIN
- status = _AOMTypeInDispose(aomPtr);
- if (returnStatus == noErr)
- returnStatus = status;
- #endif
- if (AOM.doneButton != NULL)
- DisposeControl(AOM.doneButton);
- if (AOM.ccButton != NULL)
- DisposeControl(AOM.ccButton);
- if (AOM.toButton != NULL)
- DisposeControl(AOM.toButton);
- DisposePtr((Ptr) aomPtr);
- }
- return (returnStatus);
- }
-
- /*
- * Return the panel's minimum sizes.
- */
- void
- AOMGetDimensions(
- short *minimumWidth,
- short *minimumHeight
- )
- {
- *minimumWidth = kAOMWidthMinimum;
- *minimumHeight = kAOMHeightMinimum;
- }
-
- /*
- * Move and resize in one big lump.
- */
- pascal OSErr
- AOMAdjustPanel(
- AddressOMaticPtr aomPtr,
- const Rect *boundsRect
- )
- {
- InvalRect(&BOUNDS);
- BOUNDS = *boundsRect;
- _AOMDecorateDisplay(aomPtr);
- InvalRect(&BOUNDS);
- return (noErr);
- }
-
- pascal OSErr
- AOMExtractSelection(
- AddressOMaticPtr aomPtr,
- unsigned short *selectionSize,
- PackedDSSpecPtr *selection
- )
- {
- OSErr status;
-
- switch (AOM.currentMode) {
- case kAOMEnablePDBit:
- status = _AOMPanelExtractSelection(
- aomPtr,
- AOM.pdPanel,
- selectionSize,
- selection
- );
- break;
- case kAOMEnablePanelBit:
- status = _AOMPanelExtractSelection(
- aomPtr,
- AOM.browsePanel,
- selectionSize,
- selection
- );
- break;
- case kAOMEnableFindBit:
- status = _AOMFindExtractSelection(
- aomPtr,
- selectionSize,
- selection
- );
- break;
- #ifdef ENABLE_TYPEIN
- case kAOMEnableTypeInBit:
- status = _AOMTypeInExtractSelection(
- aomPtr,
- selectionSize,
- selection
- );
- break;
- #endif
- }
- return (status);
- }
-
-
-
- /*
- * This should be done by using the identity queue instead.
- */
- pascal OSErr
- AOMSetIdentity(
- AddressOMaticPtr aomPtr, /* The panel */
- AuthIdentity userIdentity
- )
- {
- OSErr status;
- OSErr result;
-
- result = _AOMPanelSetIdentity(aomPtr, AOM.browsePanel, userIdentity);
- status = _AOMPanelSetIdentity(aomPtr, AOM.pdPanel, userIdentity);
- if (result == noErr)
- result = status;
- status = _AOMFindSetIdentity(aomPtr, userIdentity);
- if (result == noErr)
- result = status;
- /* Type-in ignores identity? */
- return (result);
- }
-
- void
- _AOMSaveState(
- register AddressOMaticPtr aomPtr,
- AOMFontStyle textFace,
- register AOMSaveStatePtr statePtr
- )
- {
- #define STATE (*statePtr)
-
- GetPort(&STATE.savePort);
- SetPort(AOM.window);
- GetPenState(&STATE.savePenState);
- STATE.textFont = qd.thePort->txFont;
- STATE.textSize = qd.thePort->txSize;
- STATE.textFace = qd.thePort->txFace;
- if (IS_COLOR(AOM.window)) {
- GetForeColor(&STATE.foregroundColor);
- GetBackColor(&STATE.backgroundColor);
- }
- _AOMSetFont(aomPtr, textFace);
- #undef STATE
- }
-
- void
- _AOMSetFont(
- register AddressOMaticPtr aomPtr,
- AOMFontStyle textFace
- )
- {
- if (IS_COLOR(AOM.window)) {
- RGBBackColor(
- (textFace == kAOMLabelFontStyle)
- ? &_AOMBackgroundColor
- : &_AOMWhiteColor
- );
- RGBForeColor(&_AOMBlackColor);
- }
- PenNormal();
- TextFont(kAOMLabelFontNumber);
- TextSize(kAOMLabelFontSize);
- TextFace(textFace);
- }
-
- void
- _AOMRestoreState(
- register AOMSaveStatePtr statePtr
- )
- {
- #define STATE (*statePtr)
-
- TextFont(STATE.textFont);
- TextSize(STATE.textSize);
- TextFace(STATE.textFace);
- if (IS_COLOR(qd.thePort)) {
- RGBBackColor(&STATE.backgroundColor);
- RGBForeColor(&STATE.foregroundColor);
- }
- SetPenState(&STATE.savePenState);
- SetPort(STATE.savePort);
- #undef STATE
- }
-